#include "Timer.h"

#include <windows.h>

CTimer::CTimer()
{

    timer = GetTickCount();
    FrameTimer = timer;
	
}

void CTimer::Update()
{

	//Calculate the new time variables
	
	//Store the current time in a temporary variable
    long Now = GetTickCount();
    
    //Calculate the elapsed time since the last frame
	elapsed = Now - timer;
	
	//Calculate quick values only once per frame
    elapsed2 = elapsed * elapsed;
    
    //if (elapsedold > 0)
	//	elapsedchange = float(elapsed) / float(elapsedold);
	//else
	//	elapsedchange = 1;
    
    //Set the old elapsed time to the current elapsed time
    //elapsedold 		= elapsed;
    
    //Update the timer
    timer 			= Now;

	//Check if a second has passed 
    if(Now - FrameTimer >= 1000){
    
    	//Calculate the FPS and reset the counter variables
        fps 		= FPSCounter + 1;
        FPSCounter 	= 0;
        FrameTimer 	= Now;
    
    }
    else{

		//Otherwise increase the FPS
        FPSCounter 	+= 1;

    }

}
